package yja.gzw.app.activity

import android.view.View
import android.widget.Toast
import androidx.lifecycle.Observer
import com.google.android.material.tabs.TabLayout
import yja.gzw.app.R
import yja.gzw.app.base.BaseActivity
import yja.gzw.app.databinding.ActivityShengqingdianzifapiaoBinding
import yja.gzw.app.model.UserData
import yja.gzw.app.viewmodel.Mainviewmodel

class ShengqingdianzifapiaoActivity :BaseActivity<Mainviewmodel, ActivityShengqingdianzifapiaoBinding>(
    R.layout.activity_shengqingdianzifapiao){

    var zhuangtais=1

    val list: MutableList<String> = mutableListOf("个人","企业")
    override fun initView() {
        val pingjie=intent.getStringExtra("pingjie")

       // Toast.makeText(this,pingjie,Toast.LENGTH_SHORT).show()
        binding.zhanshi2.visibility=View.VISIBLE

        binding.tabs.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener{
            override fun onTabSelected(tab: TabLayout.Tab) {
                if(tab.position==0){
                    zhuangtais=1
                    binding.zhanshi.visibility=View.GONE
                    binding.zhanshi2.visibility=View.VISIBLE
                }else{
                    zhuangtais=2
                    binding.zhanshi.visibility=View.VISIBLE
                    binding.zhanshi2.visibility=View.GONE
                }
            }

            override fun onTabUnselected(tab: TabLayout.Tab?) {

            }

            override fun onTabReselected(tab: TabLayout.Tab?) {

            }


        })


        for (s in list) {
                val tab = binding.tabs.newTab()
                binding.tabs.addTab(tab.setText(s))


        }





        binding.baocun.setOnClickListener {
            if(zhuangtais==1){
                val shushu=binding.shushu.text.toString()
                viewmodel.onshengqingfapiaowang(UserData.token, mapOf("type" to "1","title" to shushu,"invoice_id" to pingjie!!))

            }else{
                viewmodel.onshengqingfapiaowang(UserData.token, mapOf("type" to "2","invoice_id" to pingjie!!,"company_name" to binding.shu1.text.toString(),
                    "tax_registration_number" to binding.shu2.text.toString(),"register_address" to binding.shu3.text.toString(),
                    "register_mobile" to binding.shu4.text.toString(),"open_bank" to binding.shu5.text.toString(),"bank_name" to binding.shu6.text.toString()
                    ))

            }


        }




    }

    override fun dataObservese() {

        viewmodel.onshengqingfapiao.observe(this, Observer {
            if(it.code==1){
                Toast.makeText(this,it.msg, Toast.LENGTH_SHORT).show()
                finish()
            }else{
                Toast.makeText(this,it.msg, Toast.LENGTH_SHORT).show()
            }

        })


    }
}